package com.pda.yuanjing.dialog.fm;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.pda.yuanjing.PDApp;
import com.pda.yuanjing.R;
import com.pda.yuanjing.beanout.NoBillBeanOut;
import com.pda.yuanjing.dialog.subcode.ProductAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class FMDialog extends Dialog {
    private String TAG = "FMDialog";
    private ImageView ivexit;
    private EditText oet;
    private TextView tvzm;
    private ListView listview;
    private Button bt;
    private Context mContext;
    private View layout;
    private CodeAdapter codeAdapter;
    private List<String> mlist = new ArrayList<>();

    public void setList(List<String> list){
        mlist = list;
        codeAdapter = new CodeAdapter(mContext,mlist);
        listview.setAdapter(codeAdapter);
    }

    public void setZM(String zm){
        tvzm.setText("主码:"+zm);
    }

    public FMDialog(final Context context, int theme) {
        super(context, theme);
        layout = View.inflate(context, R.layout.dialog_fm, null);
        setContentView(layout);
        mContext = context;
        ivexit = (ImageView) layout.findViewById(R.id.ivexit);
        oet = (EditText) layout.findViewById(R.id.oet);
        tvzm = (TextView) layout.findViewById(R.id.tvzm);
        bt = (Button) layout.findViewById(R.id.bt);
        listview = (ListView) layout.findViewById(R.id.listview);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(oet.getText().toString());
            }
        });
        ivexit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public void setText(String str){
        oet.setText(str);
    }

    @Override
    public void show() {
        PDApp.scanffm = true;
        super.show();
    }


    @Override
    public void dismiss() {
        PDApp.scanffm = false;
        super.dismiss();
    }
}


